Skip to content

fix: eliminate port race in setupFakeEnvoyStats test helper - #9580

Merged
arkodg merged 1 commit into
envoyproxy:mainfrom
muwaqar:fix/shutdown-manager-port-race
Jul 26, 2026
Merged

fix: eliminate port race in setupFakeEnvoyStats test helper#9580
arkodg merged 1 commit into
envoyproxy:mainfrom
muwaqar:fix/shutdown-manager-port-race

Conversation

@muwaqar-cflt

Copy link
Copy Markdown
Contributor

Summary

setupFakeEnvoyStats in internal/cmd/envoy/shutdown_manager_test.go binds an ephemeral port with net.Listen(":0"), immediately closes that listener, and later re-binds to the same port number via s.ListenAndServe(). This is a classic time-of-check-to-time-of-use race: between l.Close() and the goroutine's ListenAndServe() actually completing its bind, another process (or a concurrently running test) can grab that exact port number, causing TestGetTotalConnections to fail intermittently on loaded machines with errors like error getting listener downstream_cx_active stat: Get ..., while the real cause (fail to listen: ...) is only printed to stdout rather than failing the test directly.

Fix

Keep the original net.Listener and call s.Serve(l) instead of s.ListenAndServe(), so the already-bound listener is reused and the port is never released and re-acquired.

Test plan

  • go build ./...
  • go test -race -run TestGetTotalConnections -count=200 ./internal/cmd/envoy/... — clean

@muwaqar-cflt
muwaqar-cflt requested a review from a team as a code owner July 25, 2026 06:34
@netlify

netlify Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploy Preview for cerulean-figolla-1f9435 ready!

Name Link
🔨 Latest commit 256ac64
🔍 Latest deploy log https://app.netlify.com/projects/cerulean-figolla-1f9435/deploys/6a645b765679b80008d09f00
😎 Deploy Preview https://deploy-preview-9580--cerulean-figolla-1f9435.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

net.Listen(":0") followed by l.Close() and a later ListenAndServe() on
the resulting port number leaves a window where another process (or a
concurrently running test) can grab that exact ephemeral port before
the re-bind happens, causing TestGetTotalConnections to fail with
connection errors on loaded machines. Serve on the already-bound
listener directly via s.Serve(l) so the port is never released.

Signed-off-by: Muhammad Waqar <mwaqar@confluent.io>
@muwaqar-cflt
muwaqar-cflt force-pushed the fix/shutdown-manager-port-race branch from 4b91931 to 256ac64 Compare July 25, 2026 06:45

@zhaohuabing zhaohuabing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@codecov

codecov Bot commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.59%. Comparing base (8782e63) to head (256ac64).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9580      +/-   ##
==========================================
- Coverage   75.64%   75.59%   -0.05%     
==========================================
  Files         252      252              
  Lines       41758    41758              
==========================================
- Hits        31589    31569      -20     
- Misses       8046     8062      +16     
- Partials     2123     2127       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zhaohuabing
zhaohuabing requested a review from a team July 25, 2026 09:23
@zhaohuabing

Copy link
Copy Markdown
Member

/retest

@arkodg
arkodg merged commit 60db84a into envoyproxy:main Jul 26, 2026
57 of 68 checks passed
@muwaqar-cflt
muwaqar-cflt deleted the fix/shutdown-manager-port-race branch July 26, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants